package com.pd.backend.service.impl;

import com.pd.backend.entity.PdTransportOrderTask;
import com.pd.backend.dao.PdTransportOrderTaskDao;
import com.pd.backend.service.PdTransportOrderTaskService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 运单与运输任务关联表(PdTransportOrderTask)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:35
 */
@Service("pdTransportOrderTaskService")
public class PdTransportOrderTaskServiceImpl implements PdTransportOrderTaskService {
    @Resource
    private PdTransportOrderTaskDao pdTransportOrderTaskDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdTransportOrderTask queryById(String id) {
        return this.pdTransportOrderTaskDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdTransportOrderTask 筛选条件
     * @param pageRequest          分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdTransportOrderTask> queryByPage(PdTransportOrderTask pdTransportOrderTask, PageRequest pageRequest) {
        long total = this.pdTransportOrderTaskDao.count(pdTransportOrderTask);
        return new PageImpl<>(this.pdTransportOrderTaskDao.queryAllByLimit(pdTransportOrderTask, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdTransportOrderTask 实例对象
     * @return 实例对象
     */
    @Override
    public PdTransportOrderTask insert(PdTransportOrderTask pdTransportOrderTask) {
        this.pdTransportOrderTaskDao.insert(pdTransportOrderTask);
        return pdTransportOrderTask;
    }

    /**
     * 修改数据
     *
     * @param pdTransportOrderTask 实例对象
     * @return 实例对象
     */
    @Override
    public PdTransportOrderTask update(PdTransportOrderTask pdTransportOrderTask) {
        this.pdTransportOrderTaskDao.update(pdTransportOrderTask);
        return this.queryById(pdTransportOrderTask.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdTransportOrderTaskDao.deleteById(id) > 0;
    }
}
